<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/template.xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">

    <ui:define name="title">
        HelpDeskRu:AdminZone
    </ui:define>

    <ui:define name="top_menu">
        <ui:include src="/admin/main_menu.xhtml"/>
    </ui:define>


    <ui:define name="content">

        <h:form id="form">

            <p:dataTable value="#{usersController.listAllUsers}" var="item" 
                         emptyMessage="" rowKey="#{item.id}" editable="true">
                
                <f:facet name="header">
                    
                    <h:outputText value="#{prop['admin.users.header']}"/>
                    <br/>
                    <div align="left">
                        <p:commandButton value="#{prop['admin.users.addNewUser']}"
                                         actionListener="#{usersController.addNewUser}"
                                         update="@form"
                                         icon="ui-icon-plus"/>                        
                    </div>
                </f:facet>


                <p:column headerText="Id">
                    <h:outputText value="#{item.id}" />
                </p:column>

                <p:column headerText="#{prop['admin.users.name']}">

                    <p:cellEditor>

                        <f:facet name="output">
                            <h:outputText value="#{item.name}" />
                        </f:facet>

                        <f:facet name="input">
                            <h:inputText value="#{item.name}" size="15"/>
                        </f:facet>

                    </p:cellEditor>

                </p:column>

                <p:column headerText="Login">
                    <p:cellEditor>

                        <f:facet name="output">
                            <h:outputText value="#{item.login}" />
                        </f:facet>

                        <f:facet name="input">
                            <h:inputText value="#{item.login}" size="15"/>
                        </f:facet>

                    </p:cellEditor>

                </p:column>


                <p:column headerText="#{prop['admin.users.role']}">

                    <p:cellEditor>

                        <f:facet name="output">
                            <h:outputText value="#{item.role.name}" />
                        </f:facet>

                        <f:facet name="input">
                            
                            <h:selectOneMenu value="#{item.role.name}">
                                <f:selectItems value="#{usersController.selectItemListRoles}"/>
                            </h:selectOneMenu>

                        </f:facet>

                    </p:cellEditor>

                </p:column>
                
                
                <p:column headerText="#{prop['admin.users.email']}">

                    <p:cellEditor>

                        <f:facet name="output">
                            <h:outputText value="#{item.email}" />
                        </f:facet>

                        <f:facet name="input">
                            <h:inputText value="#{item.email}"/>
                        </f:facet>

                    </p:cellEditor>

                </p:column>

                
                <p:column headerText="#{prop['admin.users.organization']}">
                    <p:cellEditor>

                        <f:facet name="output">
                            <h:outputText value="#{item.organization.toString()}" />
                        </f:facet>

                        <f:facet name="input">
                            
                            <h:selectOneMenu value="#{item.organization}">
                                <f:selectItems value="#{organizationController.selectItemListOrganization}"/>
                            </h:selectOneMenu>

                        </f:facet>

                    </p:cellEditor>
                    
                </p:column>
                
                
                <p:column>
                    <p:rowEditor />
                </p:column>


                <p:column> 
                    
                    <p:commandLink  value="#{prop['admin.users.changePassword']}"
                                    update=":changePasswordForm:changePasswordPanel"
                                    oncomplete="changePasswordDialog.show()">
                        <f:setPropertyActionListener target="#{usersController.currentUser}" 
                                                     value="#{item}"/>
                    </p:commandLink>

                    #{' '}
                    
                    <p:commandLink  value="#{prop['admin.users.deleteUser']}"
                                    update=":deleteUserForm:deleteUserPanel"
                                    oncomplete="deleteUserConfirmDialog.show()">
                        <f:setPropertyActionListener target="#{usersController.currentUser}" 
                                                     value="#{item}"/>
                    </p:commandLink>
                </p:column>


                <f:facet name="footer">
                    <div align="left">
                        <p:commandButton value="#{prop['admin.users.saveAll']}" actionListener="#{usersController.saveAll}"
                                         update="@form"
                                         icon="ui-icon-disk"/>
                        
                    </div>
                </f:facet>
                
            </p:dataTable>
            
            <br/>
            
            <h:outputText value="* #{prop['admin.createNewUserKomment']}" class="ui-widget"/>
            
        </h:form>

       
        
        
        
        
        
        
         
        
        <h:form id="changePasswordForm">
        
            <p:outputPanel id="changePasswordPanel">
                
                <p:dialog widgetVar="changePasswordDialog" header="#{prop['admin.users.changePasswordPanel.header']}">
                
                    <h:outputText value="#{prop['admin.users.changePasswordPanel.outputText1']} #{usersController.currentUser}"/>
                    
                    <h:panelGrid columns="2">
                        
                        <h:outputText value="#{prop['admin.users.changePasswordPanel.outputText2']}"/>
                        <h:inputSecret value="#{usersController.newUserPassword}"/>
                        
                        <h:outputText value="#{prop['admin.users.changePasswordPanel.outputText3']}"/>
                        <h:inputSecret value="#{usersController.newUserPassword2}"/>
                        
                    </h:panelGrid>
                    
                    <p:commandButton actionListener="#{usersController.saveCurrentUserPassword}" 
                                     action="/admin/users"
                                     update=":form"
                                     value="#{prop['admin.users.changePasswordPanel.save']}"
                                     oncomplete="changePasswordDialog.hide()"/>
                </p:dialog>
                            

            </p:outputPanel>
            
        </h:form>
        
        
        
        
        <h:form id="deleteUserForm">
        
            <p:outputPanel id="deleteUserPanel">
                
                <p:confirmDialog message="#{prop['admin.users.deleteUserPanel.message']} #{usersController.currentUser}?"
                                header="#{prop['admin.users.deleteUserPanel.header']}" severity="alert"
                                widgetVar="deleteUserConfirmDialog">

                    <p:commandButton value="#{prop['admin.yes']}" 
                                     actionListener="#{usersController.deleteUser}"
                                     action="/admin/users"
                                     update=":form" 
                                     oncomplete="deleteUserConfirmDialog.hide()"/>

                    <p:commandButton value="#{prop['admin.no']}" 
                                     onclick="deleteUserConfirmDialog.hide()" 
                                     type="button" />

                </p:confirmDialog>

            </p:outputPanel>
            
        </h:form>
        
        
        
        
    </ui:define>
    
</ui:composition>